<HTML>
<HEAD>
<TITLE>JavaScript Source Code 3000:  Games:  Guess 1 - 100</TITLE>
<META HTTP-EQUIV="JavaScript Source Code 3000" CONTENT = "no-cache">
<META NAME="date" CONTENT="2000-09-09">
<META NAME="channel" CONTENT="Web Developer">
<META NAME="author" CONTENT="JavaScript Source Code 3000">
<META NAME="section" CONTENT="Games">
<META NAME="description" CONTENT="Another JavaScript guess-a-number game.  However, this one automatically has a set range of 1 - 100.">

<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var js_mult1=3141
var js_mult2=5821
var js_m1=100000000
var js_m2=10000
var js_iseed=0
var js_iseed1=0
var js_iseed2=0
function random() {
if (js_iseed == 0) {
now = new Date()
js_iseed = now.getHours() + now.getMinutes() * 60 + now.getSeconds() * 3600
}
js_iseed1 = js_iseed / js_m2
js_iseed2 = js_iseed % js_m2
var tmp = (((js_iseed2 * js_mult1 + js_iseed1 * js_mult2) % js_m2) * 
js_m2 + (js_iseed2 * js_mult2)) % js_m1
js_iseed = (tmp + 1) % js_m1
return (Math.floor((js_iseed/js_m1) * 100))
}
var nGuesses = 0

function GuessNum() {
var response
var num = parseInt(document.forms[0].guess.value)
document.forms[0].guess.value = num 
nGuesses++
response = ""
if (num < myNumber)    response = response + "Higher!"
if (num > myNumber)    response = response + "Lower!"
if (num == myNumber) {
respone = "Correct!";
alert ("Right!!  Reload the page to start another game....");
}
document.forms[1].result.value=response
document.forms[1].guesses.value=nGuesses
document.forms[0].guess.focus()
document.forms[0].guess.select()
return true
}
function GiveUp() {
var response
nGuesses = 0
alert("The number was " + myNumber +".  Reload page to start a new game....");
}
// End -->
</SCRIPT>
</HEAD>

<BODY BGCOLOR=#ffffff vlink=#0000ff>

<BR>
<center>
<table width="600" cellpadding="0" cellspacing="10">
<tr>
<td width="468" align="center">

	
</td>
<td width="120" align="center">

	
</td>
</tr>
</table>
<BR>
<BR>
<BASEFONT SIZE=3>
  <FONT SIZE=6>
<B><FONT SIZE="+2" FACE="Helvetica,Arial" ALIGN=RIGHT COLOR="#0000FF">
<b><A HREF="../index.htm" /" TARGET="_top">
Home</A> </b><img src="../img/arrow.gif" /img/arrow.gif" height=13 width=7 border=0 alt="}"> <b><A HREF="index.htm" /games/"><font color="#FF0000">Games</font></A> </b>
<img src="../img/arrow.gif" /img/arrow.gif" height=13 width=7 border=0 alt="}"> <FONT COLOR="#006666">Guess 1 - 100</FONT></b></FONT><BR>
</B><BR>
  </FONT>
<table BORDER=0 WIDTH=486 CELLPADDING=3 CELLSPACING=0>
<tr><td><font FACE="helvetica,arial,geneva">
<br>
<br>
<!-- Description --><!--content_start-->

Another JavaScript guess-a-number game.  However, this one automatically has a set range of 1 - 100.
<br>
<hr>
</td></tr>
</table>
<!-- Demonstration -->
<BODY onLoad="document.forms[0].guess.focus();document.forms[0].guess.select()">
<CENTER>   
<H2>Guessing Game</H2><p>
<font size=2><b>
The object of this game is to guess the same number that the computer has guessed. The number will range from 1 to 100.<p></b></font>       
<SCRIPT>
myNumber = random();
nGuesses = 0
</SCRIPT>
<FORM onSubmit="GuessNum(); return false">
Your Guess: <INPUT TYPE="text" NAME="guess" SIZE=5>
<INPUT TYPE="button" VALUE="     Guess...   " onClick="GuessNum();">
<INPUT TYPE="button" VALUE="  GiveUp  " onClick="GiveUp();">
</FORM>
<FORM>
<CENTER>
#-Guesses: <INPUT TYPE="text" NAME="guesses" SIZE=3>
INFO: <INPUT TYPE="text" NAME="result" SIZE=10>
</CENTER>
</FORM>
<P>
<P>
<a name="source">
<table BORDER=0 WIDTH=486 CELLPADDING=3 CELLSPACING=0>
<tr><td BGCOLOR=yellow><font FACE="helvetica,arial,geneva"><b>JavaScript Source Code 3000:  Games:  Guess 1 - 100</b>
<p>Simply click inside the window below, use your cursor to highlight the script, and copy (type Control-c or Apple-c) the script into a new file in your text editor (such as Note Pad or Simple Text) and save (Control-s or Apple-s).  The script is yours!!!<br><br></font></td></tr>
<tr><td BGCOLOR=yellow ALIGN=CENTER>
<form NAME="copy">

<DIV align="center">
<input type=button value="Highlight All" onClick="javascript:this.form.txt.focus();this.form.txt.select();">&nbsp;&nbsp;&nbsp;&nbsp;
<INPUT TYPE="text" NAME="total" VALUE="Script Size:  2.55 KB  " size="24">
</DIV>

<textarea NAME="txt" ROWS=20 COLS=75 WRAP=VIRTUAL>

&lt;!-- THREE STEPS TO INSTALL GUESS 1 - 100:

   1.  Paste the coding into the HEAD of your HTML document
   2.  Add the onLoad event handler to the BODY tag
   3.  Put the last coding into the BODY of your HTML document  --&gt;
   
&lt;!-- STEP ONE: Copy this code into the HEAD of your HTML document  --&gt;

&lt;HEAD&gt;

&lt;SCRIPT LANGUAGE="JavaScript"&gt;

&lt;! &gt;
&lt;! &gt;

&lt;!-- Begin
var js_mult1=3141
var js_mult2=5821
var js_m1=100000000
var js_m2=10000
var js_iseed=0
var js_iseed1=0
var js_iseed2=0
function random(n) {
if (js_iseed == 0) {
now = new Date()
js_iseed = now.getHours() + now.getMinutes() * 60 + now.getSeconds() * 3600
}
js_iseed1 = js_iseed / js_m2
js_iseed2 = js_iseed % js_m2
var tmp = (((js_iseed2 * js_mult1 + js_iseed1 * js_mult2) % js_m2) * 
js_m2 + (js_iseed2 * js_mult2)) % js_m1
js_iseed = (tmp + 1) % js_m1
return (Math.floor((js_iseed/js_m1) * n))
}
var nGuesses = 0

function GuessNum() {
var response
var num = parseInt(document.forms[0].guess.value)
document.forms[0].guess.value = num 
nGuesses++
response = ""
if (num &lt; myNumber)    response = response + "Higher!"
if (num &gt; myNumber)    response = response + "Lower!"
if (num == myNumber) {
respone = "Correct!";
alert ("Right!!  Reload the page to start another game....");
}
document.forms[1].result.value=response
document.forms[1].guesses.value=nGuesses
document.forms[0].guess.focus()
document.forms[0].guess.select()
return true
}
function GiveUp() {
var response
nGuesses = 0
alert("The number was " + myNumber +".  Reload page to start a new game....");
}
// End --&gt;
&lt;/SCRIPT&gt;

&lt;!-- STEP TWO: Add the onLoad event handler to the BODY tag  --&gt;

&lt;BODY onLoad="document.forms[0].guess.focus();document.forms[0].guess.select()"&gt;

&lt;!-- STEP THREE:  Put the last code into the BODY of your HTML document --&gt;

&lt;CENTER&gt;   
&lt;H2&gt;Guessing Game&lt;/H2&gt;&lt;p&gt;
&lt;font size=2&gt;
Guess the same number that the computer has guessed. The number will range from 1 to 100.&lt;p&gt;Reload the page to start a new game.&lt;/font&gt;&lt;SCRIPT&gt;
myNumber = random();
nGuesses = 0
&lt;/SCRIPT&gt;
&lt;FORM onSubmit="GuessNum(); return false"&gt;
Your Guess: &lt;INPUT TYPE="text" NAME="guess" SIZE=5&gt;
&lt;INPUT TYPE="button" VALUE="     Guess...   " onClick="GuessNum();"&gt;
&lt;INPUT TYPE="button" VALUE="  GiveUp  " onClick="GiveUp();"&gt;
&lt;/FORM&gt;
&lt;FORM&gt;
&lt;CENTER&gt;
#-Guesses: &lt;INPUT TYPE="text" NAME="guesses" SIZE=3&gt;
INFO: &lt;INPUT TYPE="text" NAME="result" SIZE=10&gt;
&lt;/CENTER&gt;
&lt;/FORM&gt;

 

&lt;!-- Script Size:  2.55 KB  --&gt;
</textarea><br><font FACE="helvetica,arial,geneva"></font></td></tr>

</table>
</form>
</FONT>
</CENTER>


</center>
</body></html>